<template>
  <div>
    <h2>保险产品展示</h2>
    <el-table
      :data="pageData.data.filter(data => !search || data.productName.toLowerCase().includes(search.toLowerCase()))"
      border
      ref="filterTable"
      lazy
      :default-sort="{prop: 'date', order: 'descending'}"
      size="medium"
      style="width: 100%"
    >
      <el-table-column label="编号" prop="_id"></el-table-column>
      <el-table-column prop="imgname" label="头像" width>
        <template slot-scope="scope">
          <img
            width="50"
            v-if="scope.row.imgname"
            :src="'http://localhost:3000/images/' + scope.row.imgname"
            alt
          />
          <img width="50" v-else src="http://localhost:3000/images/default.jpg" alt />
        </template>
      </el-table-column>
      <el-table-column label="产品名称" prop="productName"></el-table-column>
      <el-table-column sortable label="生成时间" prop="opentime"></el-table-column>
       <el-table-column sortable label="详情" prop="detail"></el-table-column>
      <el-table-column label="有效年限" prop="limittime"></el-table-column>
      <el-table-column label="状态" prop="state"></el-table-column>
      <el-table-column
        label="所属类别"
        prop="categoryId.categoryName"
      >
      </el-table-column>
      <el-table-column align="right">
        <template slot="header" slot-scope="scope">
          <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
        </template>
        <template slot-scope="scope">
          <el-button size="mini" @click="getproductid1(scope.row._id)">Edit</el-button>
          <el-button size="mini" type="danger" @click="delectone1(scope.row._id)">Delete</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Page></Page>
  </div>
</template>

<script>
import Page from "../page/productpage.vue";
import { createNamespacedHelpers } from "vuex";
const { mapState, mapActions } = createNamespacedHelpers("products");

export default {
  components: {
    Page,
  },
  data() {
    return {
      activeName: "first",
      search: "",
      val1: "",
    };
  },
  computed: {
    ...mapState(["pageData", "update", "searchdata"]),
  },
  created() {
    this.showproducts();
  },
  methods: {
    ...mapActions(["showproducts", "delectone", "getproductid"]),
    //删除
    delectone1(_id) {
      this.delectone(_id);
    },
    //获取要修改的种类的id
    getproductid1(_id) {
      // this.getproductid(_id);
      this.$router.push("/system/changeproduct/" + _id);
    },
    choose: function (val) {
      let data = this.$refs["cascaderkind"].getCheckedNodes();
      console.log(data[0].label);
    },
     filterTag(value, row) {
       console.log(value, row);
        return row.tag === value;
      },
      filterHandler(value, row, column) {
        console.log(value, row, column);
        const property = column['property'];
        return row[property] === value;
      },
    
  },
};
</script>